package aw;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import utils.string_parse.StringParse;

import common_interfaces.AgentInterface;

public class Agent {
	
	private String _id;
	private Integer _team;
	private AgentInterface _reference;
	private String _position;
	private String _agentState;
	private int	_gold;
	private int _health;
	private ArrayList<String> _agentCollection = new ArrayList<String>();
	private Integer _roomID;
	private String _roomDim;
	
	

	public Agent(String id, Integer team, AgentInterface reference, String position, String agentState, Integer roomID, String roomDim){
		_id = id;
		_team = team;
		_reference = reference;
		_position = position;
		set_agentState(agentState); //Inicia tb o gold e o health
		_roomID = roomID;
		_roomDim = roomDim;
		this.set_agentCollectionADD("a");
		this.set_agentCollectionADD("b");
		this.set_agentCollectionADD("c");
		this.set_agentCollectionADD("d");
	}

	
	public int get_gold() {
		return _gold;
	}


	public void set_gold(int _gold) {
		this._gold = _gold;
	}


	public int get_health() {
		return _health;
	}


	public void set_health(int _health) {
		this._health = _health;
	}


	public Integer get_roomID() {
		return _roomID;
	}


	public void set_roomID(Integer _roomID) {
		this._roomID = _roomID;
	}


	public String get_roomDim() {
		return _roomDim;
	}


	public void set_roomDim(String _roomDim) {
		this._roomDim = _roomDim;
	}


	public ArrayList<String> get_agentCollection() {
		return _agentCollection;
	}
	
	public String get_agentCollection_ToString() {
		String resultado = "";
		
		Set<String> unique = new HashSet<String>(this._agentCollection);
		for (String key : unique) {
			resultado += "#" + key + ":" + Collections.frequency(this._agentCollection, key);
		}
		
		/*
		if(this._agentCollection.size()>0)
			resultado += this._agentCollection.get(0);
		for(int i=1; i<this._agentCollection.size(); i++){
			resultado += "#" + this._agentCollection.get(i);
		}*/
				
		if(this._agentCollection.size() > 0)
			return resultado.substring(1);
		else return resultado;
	}

	public void set_agentCollectionADD(String _agentCollection) {
		this._agentCollection.add(_agentCollection);
	}

	public String get_agentState() {
		return _agentState;
	}

	public void set_agentState(String _agentState) {
		this._agentState = _agentState;
		String[] agState = _agentState.split("[*]");
		set_gold(Integer.parseInt(agState[0]));
		set_health(Integer.parseInt(agState[1]));
	}
	
	public String getPosition() {
		return _position;
	}

	public void setPosition(String position) {
		this._position = position;
	}
	
	public String get_id() {
		return _id;
	}

	public void set_id(String _id) {
		this._id = _id;
	}

	public Integer get_team() {
		return _team;
	}

	public void set_team(Integer _team) {
		this._team = _team;
	}

	public AgentInterface get_reference() {
		return _reference;
	}

	public void set_reference(AgentInterface _reference) {
		this._reference = _reference;
	}

	public String get_RoomObjects() {
		return StringParse.objectJoin(Static_Variables.objectsByRoom.get(_roomID));
	}

}
